<template>
  <div class="app-container">
    <div class="head">
      <div class="head_detail_l">
        <img class="card_img" :src="info.cover" alt="">
        <span>卡图</span>
      </div>
      <div class="head_detail_c">
        <div class="detail">
          <div class="detail_l">数字权益卡名称：</div>
          <div>{{info.cardName}}</div>
        </div>
        <div class="detail">
          <div class="detail_l">权益卡类型：</div>
          <div>
            <dict-tag :options="cardFunctionOptions" :value="info.functionType" />
          </div>
        </div>
        <div class="detail">
          <div class="detail_l">DDCid：</div>
          <div>{{info.ddc}}</div>
        </div>
        <div class="detail">
          <div class="detail_l">发行方：</div>
          <div>{{info.name}}</div>
        </div>
        <div class="detail">
          <div class="detail_l">上链时间：</div>
          <div>{{info.chainTime}}</div>
        </div>
        <div class="detail">
          <div class="detail_l">单价（￥）：</div>
          <div>{{info.price}}</div>
        </div>
        <div class="detail">
          <div class="detail_l">交易哈希：</div>
          <div>{{info.voucher}}</div>
        </div>
        <div class="detail">
          <div class="detail_l">当前权益：</div>
          <div>{{info.equityName}}</div>
        </div>
      </div>
      <div class="head_detail_r">
        <p style="margin-bottom: 10px">
          <el-button type="primary" size="small" @click="historicalConfiguration(id)">历史权益</el-button>
        </p>
        <p>
          <el-button type="primary" size="small" @click="openEquity" v-if="info.equityIssueStatus==1">权益发放</el-button>
        </p>
      </div>
    </div>
    <div class="listBox">
      <div class="listBox_head">
        <el-form :model="queryParams" ref="queryForm" :inline="true" :label-width="labelWidth">
          <el-form-item label="卡编号：" prop="">
            <el-input v-model="queryParams.cardNo" placeholder="请输入卡编号" clearable />
          </el-form-item>
          <el-form-item label="获取来源：" prop="">
            <el-select v-model="queryParams.source" placeholder="请选择" clearable style="width: 240px">
              <el-option v-for="dict in acquisitionMethod" :key="dict.id" :label="dict.value" :value="dict.id" />
            </el-select>
          </el-form-item>
          <el-form-item label="上链时间：" prop="">
            <el-date-picker v-model="date" type="daterange" value-format="yyyy-MM-dd" range-separator="至"
              start-placeholder="开始日期" end-placeholder="结束日期">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="持卡人姓名：" prop="">
            <el-input v-model="queryParams.name" placeholder="请输入持卡人姓名" clearable />
          </el-form-item>
          <el-form-item label="手机号码：" prop="">
            <el-input v-model="queryParams.phone" placeholder="请输入手机号码" clearable />
          </el-form-item>
          <el-form-item label="权益状态：" prop="">
            <el-select v-model="queryParams.equityStatus" placeholder="请选择" clearable style="width: 240px">
              <el-option v-for="dict in statusOptions" :key="dict.id" :label="dict.value" :value="dict.id" />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
      <p style="margin-bottom:20px">
        <export-excel-button title="持卡明细" action="/equityManager/equityCard/customer/card/export"
          :params="ExportParams" />
      </p>
      <el-table v-loading="loading" :data="tableList" stripe border v-if="type != 'nfrIssue'">
        <el-table-column label="序号" align="center" type="index" width="64px" />
        <el-table-column label="卡编号" align="center" prop="cardNo" :show-overflow-tooltip="true" />
        <el-table-column label="持卡人姓名" align="center" prop="name" :show-overflow-tooltip="true" />
        <el-table-column label="手机号码" align="center" prop="phone" :show-overflow-tooltip="true" />
        <el-table-column label="持卡天数" align="center" prop="dayNum" :show-overflow-tooltip="true" />
        <el-table-column label="上链时间" align="center" prop="chainTime" width="160" :show-overflow-tooltip="true" />
        <!-- <el-table-column label="获取来源" align="center" prop="sourceStr" :show-overflow-tooltip="true" /> -->
        <el-table-column label="获取来源" align="center" prop="" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <dict-tag :options="acquisitionMethod" :value="scope.row.source" />
          </template>
        </el-table-column>
        <el-table-column label="当前权益状态" align="center" prop="equityStatusStr" :show-overflow-tooltip="true" />
        <el-table-column label="历史权益" align="center" width="120" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button size="mini" type="text" @click="handleView(scope.row)" v-if="scope.row.status!=1">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-table v-loading="loading" :data="tableList" stripe border v-if="type == 'nfrIssue'">
        <el-table-column label="序号" align="center" type="index" width="64px" />
        <el-table-column label="卡编号" align="center" prop="cardNo" :show-overflow-tooltip="true" />
        <el-table-column label="持卡人姓名" align="center" prop="name" :show-overflow-tooltip="true" />
        <el-table-column label="手机号码" align="center" prop="phone" :show-overflow-tooltip="true" />
        <el-table-column label="持卡天数" align="center" prop="dayNum" :show-overflow-tooltip="true" />
        <el-table-column label="上链时间" align="center" prop="chainTime" width="160" :show-overflow-tooltip="true" />
        <!-- <el-table-column label="获取来源" align="center" prop="sourceStr" :show-overflow-tooltip="true" /> -->
        <el-table-column label="获取来源" align="center" prop="" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <dict-tag :options="acquisitionMethod" :value="scope.row.source" />
          </template>
        </el-table-column>
        <el-table-column label="当前权益状态" align="center" prop="equityStatusStr" :show-overflow-tooltip="true" />
      </el-table>
      <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getList"></pagination>
    </div>
    <Dialog ref="dialog" @refresh="getList"></Dialog>
    <DialogTwo ref="dialogTwo" @refresh="getList"></DialogTwo>
    <DialogThree ref="dialogThree" @refresh="getEquityCard"></DialogThree>
  </div>
</template>

<script>
  import {
    customerCardLs,
    getEquityCard
  } from "@/api/equityManager/equityCard";
  import Dialog from "@/views/equityManager/cardDetails/dialog";
  import DialogTwo from "@/views/equityManager/cardDetails/dialogTwo";
  import DialogThree from "@/views/equityManager/cardDetails/dialogThree";
  import ExportExcelButton from "@/components/ExportExcelButton/index";
  // import {
  //   getSelectList
  // } from "@/api/common";
  export default {
    // dicts: ['equity_card_status', ],
    name: "",
    components: {
      Dialog,
      DialogTwo,
      DialogThree,
      ExportExcelButton
    },
    data() {
      return {
        labelWidth: '100px',
        //日期
        date: [],
        id: '',
        equityIssueId: '',
        info: {}, //权益卡信息
        cardFunctionOptions: [], //卡功能字典
        // 遮罩层
        loading: false,
        // 总条数
        total: 0,
        // 表格数据
        tableList: [],
        acquisitionMethod: [], //获取方式数组
        statusOptions: [], //用户权益卡权益状态下拉
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          equityCardId: null, //数字权益卡id
          cardNo: null, //卡编号
          chainTimeEnd: null, //上链结束时间
          chainTimeStart: null, //上链开始时间
          equityStatus: null, //权益状态 1 已激活 2 未激活
          name: null, //持卡人姓名
          phone: null, //手机号码
          source: null, //获取来源 1盲盒抽取 2空投获赠 3 发行购买 4转赠获取
        }
      };
    },
    computed: {
      ExportParams() {
        const params = {
          ...this.queryParams,
        };
        return params;
      },
    },
    created() {
      this.id = this.$route.query.id;
      this.equityIssueId = this.$route.query.equityIssueId;
      this.type = this.$route.query.type;  //nfrIssue
      this.getCardDict();
      this.getEquityStatusDict();
      this.getEquityCard();
      this.getDict();
      this.getList();
    },
    methods: {
      //获取获取来源字典
      getDict() {
        var dictType = "customer_equity_card_source";
        this.$getSelectList(dictType)
          .then((res) => {
            this.acquisitionMethod = res.result[0].dictList;
          })
          .finally(() => {
            this.loading = false;
          });
      },
      //获取用户权益卡权益状态字典
      getEquityStatusDict() {
        var dictType = "customer_equity_status";
        this.$getSelectList(dictType)
          .then((res) => {
            this.statusOptions = res.result[0].dictList;
          })
          .finally(() => {
            this.loading = false;
          });
      },
      //获取卡功能字典
      getCardDict() {
        var dictType = "equity_function_type";
        this.$getSelectList(dictType)
          .then((res) => {
            this.cardFunctionOptions = res.result[0].dictList;
          })
          .finally(() => {

          });
      },
      //获取数字权益卡详细信息
      getEquityCard() {
        getEquityCard(this.id).then(res => {
          this.info = res.result
        }).catch(() => {

        });
      },
      /** 查询列表 */
      getList() {
        this.loading = true;
        this.queryParams.equityCardId = this.id
        customerCardLs(this.queryParams).then(response => {
          this.tableList = response.result.records;
          this.total = response.result.total;
          this.loading = false;
        });
      },
      // 表单重置
      reset() {
        this.date = []
        this.queryParams = {
          pageNum: 1,
          pageSize: 10,
          equityCardId: null, //数字权益卡id
          cardNo: null, //卡编号
          chainTimeEnd: null, //上链结束时间
          chainTimeStart: null, //上链开始时间
          equityStatus: null, //权益状态 1 已激活 2 未激活
          name: null, //持卡人姓名
          phone: null, //手机号码
          source: '', //获取来源 1盲盒抽取 2空投获赠 3 发行购买 4转赠获取
        };
        // this.resetForm("form");
        // this.handleQuery()
      },
      /** 打开历史权益 */
      historicalConfiguration(id) {
        this.$refs.dialog.open(id);
      },
      /** 打开权益发放 */
      openEquity() {
        this.$refs.dialogThree.open(this.id, this.info.equityIssueId);
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.queryParams.chainTimeStart = this.date[0];
        this.queryParams.chainTimeEnd = this.date[1];
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        // this.resetForm("queryForm");
        this.reset();
        this.handleQuery();
      },
      /** 查看详情按钮操作 */
      handleView(row) {
        this.$refs.dialogTwo.open(row.id);
      },
    }
  };

</script>
<style scoped>
  .head {
    box-shadow: 0px 4px 12px 0px rgb(1 41 99 / 6%);
    background-color: #fff;
    border-radius: 8px;
    padding: 20px 20px 20px;
    display: flex;
    align-items: center;
  }

  .head_detail_l {
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 14px;
  }

  .head_detail_l .card_img {
    width: 100px;
    /* height: 80px; */
    border-radius: 4px;
    margin-bottom: 10px;
  }

  .head_detail_c {
    display: flex;
    flex-wrap: wrap;
    margin: 0 20px;
    flex: 1;
  }

  .head_detail_c .detail {
    margin: 0 10px 14px 0;
    font-size: 14px;
    color: #606266;
    display: flex;
    min-width: 270px;
  }

  .head_detail_c .detail .detail_l {
    width: 130px;
    text-align: right;
    font-size: 15px;
  }

  .head_detail_r {
    display: flex;
    flex-direction: column;
  }

  .listBox {
    box-shadow: 0px 4px 12px 0px rgb(1 41 99 / 6%);
    background-color: #fff;
    border-radius: 8px;
    padding: 20px 20px;
    margin-top: 10px;
  }

  .listBox_head {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

</style>
